﻿
Partial Public Class ucConfigReport
    Dim db As ATSDataClassesDataContext = New ATSDataClassesDataContext
    Private Sub buttonSave_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles buttonSave.Click
        My.Settings.reportLocation = textboxReportFilesLocation.Text
        My.Settings.reportHeaderShowAmounts = CheckBoxShowAmount.IsChecked
        My.Settings.Save()
        Dim companyDetails = From compDet In db.CompanyDetails
        With companyDetails.FirstOrDefault
            .CompanyName = textboxReportHeaderCompany.Text
        End With
        db.SubmitChanges()

        RibbonMain.isDirty = False
        enablebuttons(RibbonMain.isDirty)
        MsgBox("Your settings were saved successfully.", MsgBoxStyle.OkOnly, "Save...")
    End Sub

    Sub enablebuttons(ByVal enable As Boolean)
        If Not buttonCancel Is Nothing Then
            buttonCancel.IsEnabled = enable
            buttonSave.IsEnabled = enable
        End If

    End Sub

    Private Sub ucReaderSettings_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Dim companyDetails = From compDetails In db.CompanyDetails _
                                     Select compDetails.CompanyName
        textboxReportFilesLocation.Text = My.Settings.reportLocation
        textboxReportHeaderCompany.Text = companyDetails.FirstOrDefault
        CheckBoxShowAmount.IsChecked = My.Settings.reportHeaderShowAmounts
        RibbonMain.isDirty = False
        enablebuttons(RibbonMain.isDirty)
    End Sub

    Private Sub buttonCancel_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles buttonCancel.Click
        textboxReportFilesLocation.Text = My.Settings.reportLocation
        RibbonMain.isDirty = False
        enablebuttons(RibbonMain.isDirty)
    End Sub




    Private Sub buttonBrowseReport_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles buttonBrowseReport.Click
        Dim dlg As New System.Windows.Forms.FolderBrowserDialog
        dlg.SelectedPath = textboxReportFilesLocation.Text
        If dlg.ShowDialog() = Forms.DialogResult.OK Then
            textboxReportFilesLocation.Text = dlg.SelectedPath
        Else
            textboxReportFilesLocation.Text = My.Settings.reportLocation
        End If
    End Sub

    Private Sub textboxReportFilesLocation_TextChanged(ByVal sender As Object, ByVal e As System.Windows.Controls.TextChangedEventArgs) Handles textboxReportFilesLocation.TextChanged
        RibbonMain.isDirty = True
        enablebuttons(RibbonMain.isDirty)
    End Sub


    Private Sub textboxReportHeaderCompany_TextChanged(ByVal sender As Object, ByVal e As System.Windows.Controls.TextChangedEventArgs) Handles textboxReportHeaderCompany.TextChanged
        RibbonMain.isDirty = True
        enablebuttons(RibbonMain.isDirty)
    End Sub

    Private Sub CheckBoxShowAmount_Checked(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles CheckBoxShowAmount.Checked, CheckBoxShowAmount.Unchecked
        RibbonMain.isDirty = True
        enablebuttons(RibbonMain.isDirty)
    End Sub
End Class
